<template>
	<view class="games">
		<image :src="bgImg" class="bg"></image>
		<view class="btn" @click="toMenus">进入</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			windowWidth:0,
			userinfo:null,
			bgImg:null
		}
	},
	onResize(newSize) {
		// 当屏幕方向变化时，重新加载页面
		console.log(newSize.size.windowWidth)
	},
	onLoad() {
		plus.screen.lockOrientation('landscape-primary'); // 强制横屏
	},
	methods: {
		refreshPage() {
			// 刷新页面
			uni.reLaunch({
				url: '/pages/client/games/index'
			});
		},
		toMenus() {
			uni.navigateTo({
				url: '/pages/client/games/menus'
			});
		},
		//首页主配置
		getConfig() {
			uni.request({
				url: this.configs.gameUrl + '/play/mMainConfig/queryById',
				method: 'GET',
				header: {
					'X-Access-Token': this.configs.userToken // 在header中添加token
				},
				data: {
					id: '1799522105948135426',
					userId: this.configs.userId
				},
				success: data => {
					//存储到缓存
					uni.setStorageSync('mainImg', data.data.result.mainImage)
					uni.setStorageSync('backgroundImage', data.data.result.backgroundImage)
					uni.setStorageSync('storyBackgroundImage', data.data.result.storyBackgroundImage)
				 },
				fail: (data, code) => { }
			});
		},
		getBgImg(){
			uni.request({
				url: this.configs.gameUrl + '/play/mFile/list',
				method: 'GET',
				header: {
					'X-Access-Token': this.configs.userToken // 在header中添加token
				},
				data: {
					resourceId: uni.getStorageSync('mainImg'),
					userId: this.configs.userId
				},
				success: data => {
					this.bgImg = data.data.result.records[0].url
				 },
				fail: (data, code) => { }
			});
		},
		//章节列表
		getChapterList() {
			uni.request({
				url: this.configs.gameUrl + '/play/mChapter/list',
				method: 'GET',
				header: {
					'X-Access-Token': this.configs.userToken // 在header中添加token
				},
				data:{
					userId: this.configs.userId
				},
				success: data => {
					this.getStoreInfo(data.data.result.records[1].id)
					this.getStoreLine()
				},
				fail: (data, code) => { }
			});
		},
		//用章节ID获取故事情节
		getStoreInfo(id) {
			uni.request({
				url: this.configs.gameUrl + '/play/mStoryInfo/list',
				method: 'GET',
				header: {
					'X-Access-Token': this.configs.userToken // 在header中添加token
				},
				data: {
					chapterId: id,
					userId: this.configs.userId
				},
				success: data => {
					//resourceId视频资源ID
					this.getVideoInfo(data.data.result.records[1].resourceId)

				},
				fail: (data, code) => { }
			});
		},
		//根据视频ID拿资源
		getVideoInfo(id) {
			uni.request({
				url: this.configs.gameUrl + '/play/mFile/list',
				method: 'GET',
				header: {
					'X-Access-Token': this.configs.userToken // 在header中添加token
				},
				data: {
					resourceId: id,
					userId: this.configs.userId
				},
				success: data => {
					//resourceId视频资源ID
				},
				fail: (data, code) => { }
			});
		},
		//故事线    故事线+故事情节生成图
		getStoreLine() {
			uni.request({
				url: this.configs.gameUrl + '/play/mStoryLine/list',
				method: 'GET',
				header: {
					'X-Access-Token': this.configs.userToken // 在header中添加token
				},
				data: {
					userId: this.configs.userId
				},
				success: data => { },
				fail: (data, code) => { }
			});
		}
	},
	onShow() {
		console.log(this.configs)
		// this.getChapterList()
		this.getConfig()
		this.getBgImg()
	}
}
</script>

<style lang="less" scoped>
.games {
	width: 100%;
	height: 100vh;

	.bg {
		position: absolute;
		width: 100%;
		height: 100vh;
		left: 0;
		top: 0;
	}

	.btn {
		width: 200rpx;
		height: 48rpx;
		background: linear-gradient(45deg, #ff8080, #ffff80);
		border-radius: 24rpx;
		text-align: center;
		line-height: 48rpx;
		position: fixed;
		bottom: 40rpx;
		left: 50%;
		transform: translateX(-50%);
		color: #fff;
		font-size: 20rpx;

	}
}
</style>